package com.itheima.mapper;


import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.QueryPageBean;
import com.itheima.pojo.*;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.Date;
import java.util.List;

@Mapper
public interface OrderDao {
    
    @Select("select count(*) from t_order")
    Long findCount();

    List<OrderVO> findPage(int start, int end, String queryString);

    @Update("update t_order set orderStatus = #{orderStatus} where id = #{id}")
    void update(Order order);

    @Select("select o.orderType,m.name as member,o.orderDate,s.code as setmeal from t_order o,t_member m ,t_setmeal s where o.member_id = m.id and o.setmeal_id = s.id and o.id = #{id}")
    OrderVO2 findById(Integer id);

    @Select("select o.id from t_order o , t_member m where o.member_id = m.id and o.orderDate=#{orderDate} and o.setmeal_id = #{setmealId} and m.name=#{name}")
    Long findByNameAndOrderDateAndSetmeal(OrderTOD orderTOD);

    @Insert("insert into t_order(member_id,orderDate,orderType,orderStatus,setmeal_id) values (#{memberId},#{orderDate},#{orderType},#{orderStatus},#{setmealId})")
    void add(Order order);

    @Select("select count(*) from t_order where orderDate = #{reportData} and orderStatus = #{orderStatus}")
    Integer findMemberCountByDate(String reportData, String orderStatus);

    @Select("select count(*) from t_order where orderDate >= #{start} and orderDate <= #{end} and orderStatus = #{orderStatus}")
    Integer findVisitsNumberCountByWeek(Date start, Date end, String orderStatus);


    @Select("select count(*) from t_order where orderDate like concat(#{reportMonth},'%')")
    Integer getMemberCountByMonth(String reportMonth);

    @Select("select count(*) from t_order where orderDate like concat(#{reportMonth},'%') and orderStatus = #{orderStatus}")
    Integer getMonthVisistsCountByMonth(String reportMonth, String orderStatus);

    @Select("select count(*) from t_order where orderDate = #{reportData}")
    Integer findCountByDate(String reportData);


    @Select("select count(*) from t_order where orderDate >= #{start} and orderDate <= #{end}")
    Integer findOrderCountByWeek(Date start, Date end);

    @Select("select s.name from t_order o,t_setmeal s where o.setmeal_id=s.id  group by s.name")
    List<String> findName();

    @Select("select count(*) from t_order o,t_setmeal s where o.setmeal_id=s.id and s.name = #{name}")
    Integer findCountByName(String name);
}
